/**
 * Copyright (c) 2010 Andrey Somov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.yaml.scalayaml.scanner

import java.util.regex.Pattern

object Constant {
    val LINEBR_S = "\n\u0085\u2028\u2029"
    val FULL_LINEBR_S = "\r" + LINEBR_S
    val NULL_OR_LINEBR_S = "\0" + FULL_LINEBR_S
    val NULL_BL_LINEBR_S = " " + NULL_OR_LINEBR_S
    val NULL_BL_T_LINEBR_S = "\t" + NULL_BL_LINEBR_S
    
    abstract class V(value: String) {
        def has(ch: Char, additional: String = null): Boolean = {
            if (value.indexOf(ch) != -1)
                return true
            if (additional != null)
                additional.indexOf(ch) != -1
            else
                false
        }
    
        def hasNo(ch: Char, additional: String = null) = {
            !has(ch, additional)
        }
    }
    object LINEBR extends V (LINEBR_S)
    object FULL_LINEBR extends V (FULL_LINEBR_S)
    object NULL_OR_LINEBR extends V (NULL_OR_LINEBR_S)
    object NULL_BL_LINEBR extends V (NULL_BL_LINEBR_S)
    object NULL_BL_T_LINEBR extends V (NULL_BL_T_LINEBR_S)
    
    
    val ALPHA = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"
    val NOT_HEXA: scala.util.matching.Regex = "[^0-9A-Fa-f]".r
    val ESCAPE_REPLACEMENTS = Map(
        '0' -> "\0",
        'a' -> "\u0007",
        'b' -> "\u0008",
        't' -> "\u0009",
        'n' -> "\n",
        'v' -> "\u000B",
        'f' -> "\u000C",
        'r' -> "\r",
        'e' -> "\u001B",
        ' ' -> "\u0020",
        '"' -> "\"",
        '\\' -> "\\",
        'N' -> "\u0085",
        '_' -> "\u00A0",
        'L' -> "\u2028",
        'P' -> "\u2029"        
    )
    val ESCAPE_CODES = Map(
        'x' -> 2,
        'u' -> 4,
        'U' -> 8
    )
}

